Installing A Screensaver - Two Methods

Last Updated: 1st May

METHOD ONE:

In your windows directory you should be able to find a program called rundll32.exe. This program, among many other things, can install a screensaver. The trick is in knowing what parameters to use. Find a screensaver which is not currently installed. Choose the Run option on the Start Menu and input the following:

rundll32 desk.cpl,InstallScreenSaver C:\Windows\Red Balloons.scr

Instead of C:\Windows\Red Balloons.scr you should input the screensaver of your choice. Hopefully, what you observed is the screensaver tab of the Display Properties window notifying you that your screensaver has been installed. In Delphi, then, we'll use the ExecuteFile function, which is found in the FMXUtils unit (in the Demos\Doc\Filmanex directory!):

ExecuteFile('rundll32.exe',
'desk.cpl,InstallScreenSaver C:\Windows\Red Balloons.scr',
'',
SW_SHOW);

Note that you shouldn't hard code the windows directory as I have done here. GetWindowsDirectory is the way to go.

METHOD TWO:

One potential problem with the above method is that it is not transparent to the user. On some rare occasions, you will want to install a screensaver without the user needing to know. The solution to this problem would cause users of other 32-bit operating systems to snigger, but so be it. We will have to go back to those 16-bit INI files. Specifically, System.ini. Inside that file, under the boot section, you will find the SCRNSAVE.EXE key. This key holds the name of the screensaver file. Unfortunately, because of its 16-bit roots, the name must conform to the old 8.3 short filename format. So what do we do with Red Balloons.scr? Fortunately, there is a function which converts long filenames to short filenames. Here, then, is a procedure which will install a screensaver quietly:


procedure InstallScreensaver(path, filename : String);
var
  saverstr, savershort, saverlong : String;
begin
  saverlong := path + filename;
  SetLength(saverstr, 256);
  SetLength(savershort, 256);

// First check out the currently installed screensaver

  GetPrivateProfileString('boot', 'SCRNSAVE.EXE', 'Missing',
                          PChar(saverstr), Length(saverstr), 
'SYSTEM.INI'
); // Convert your long screensaver filename to a short filename. GetShortPathName(PChar(saverlong), PChar(savershort), 256); // If the current screensaver is different from yours then // we should write to the ini file. if UpperCase(saverstr) <> UpperCase(savershort) then WritePrivateProfileString('boot', 'SCRNSAVE.EXE', PChar(savershort), 'SYSTEM.INI'); end;
lonewolf@tig.com.au